package com.atguigu.lease.web.app.service.impl;



import com.atguigu.lease.model.entity.GraphInfo;

import com.atguigu.lease.web.app.mapper.GraphInfoMapper;
import com.atguigu.lease.web.app.service.GraphService;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GraphServiceImpl implements GraphService {

    @Autowired
    private GraphInfoMapper graphMapper;

    /**
     * 根据关联ID和类型获取图片列表
     * 实现思路：
     * 1. 根据关联ID和类型查询图片信息
     * 2. 将图片信息转换为GraphVo返回
     */
    @Override
    public List<GraphVo> getGraphVoListByRelatedId(Long relatedId, Integer type) {
        LambdaQueryWrapper<GraphInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GraphInfo::getItemId,relatedId)
                   .eq(GraphInfo::getItemType, type)
                   .eq(GraphInfo::getIsDeleted, 0);
        
        List<GraphInfo> graphList = graphMapper.selectList(queryWrapper);
        List<GraphVo> result = new ArrayList<>();
        
        for (GraphInfo graph : graphList) {
            GraphVo graphVo = new GraphVo();
            BeanUtils.copyProperties(graph, graphVo);
            result.add(graphVo);
        }
        
        return result;
    }
}